package com.dw.widget.slideshow.utils.db;

import android.content.Context;

/**
 * 数据库数据对象实例类
 * @author DaiYu
 *
 */
public class DataObject {

	private long _id = -1;

	public final long getId() {
		return _id;
	}

	public final void setId(long id) {
		this._id = id;
	}
	
	private DataBaseHelper dbHelper;
	
	public final DataBaseHelper getDbHelper() {
		return dbHelper;
	}

	public final void setDbHelper(DataBaseHelper dbHelper) {
		this.dbHelper = dbHelper;
	}

	/**
	 * 如果希望使用其中的数据库部分必须调用本构造函数
	 * @param context
	 * @param tableName
	 */
	public DataObject(Context context, String db)
	{
		dbHelper = new DataBaseHelper(context, db, this.getClass());
	}
	
	public DataObject()
	{
		
	}
	
	public long insert() throws Exception
	{
		if(dbHelper == null)
		{
			throw(new Exception("Database Helper is NULL"));
		}
		
		return dbHelper.insert(this);
	}
	
	public int update() throws Exception
	{
		if(dbHelper == null)
		{
			throw(new Exception("Database Helper is NULL"));
		}
		
		return dbHelper.update(this);
	}
	
	public int delete() throws Exception
	{
		if(dbHelper == null)
		{
			throw(new Exception("Database Helper is NULL"));
		}
		
		return dbHelper.delete(this);
	}
}
